<template>
  <div>
    <div><el-button type="primary" @click="goBack()">返回</el-button></div>
    <div class="relationContent">
      <div class="first">
        <div class="d_flex" style="margin-right: 10px;">
          <div class="avtor"><img :src="SaleRelation.avatar" alt=""></div>
          <div class="phone">{{ SaleRelation.phone }}</div>
          <div class="name">{{ SaleRelation.nickname }}</div>
        </div>
        <div class="line"></div>
        <div class="second">
          <div v-for="(item, index) in SaleRelation.children" class="first">
            <div class="yaxis" :style="{ height: setMargin(3, index, item.children, SaleRelation.children) , marginTop: setMargin(1, index, item.children, SaleRelation.children), marginBottom: setMargin(2, index, item.children, SaleRelation.children) }"></div>
            <div class="line"></div>
            <div style="margin: 15px 0;">
              <div class="d_flex" style="margin-right: 10px;">
                <div class="avtor"><img :src="item.avatar" alt=""></div>
                <div class="phone">{{ item.phone }}</div>
                <div class="name">{{ item.nickname }}</div>
              </div>
            </div>
            <div v-if="item.children.length>0" class="line"></div>
            <div class="second second1">
              <div v-for="itemChildren in item.children" class="first">
                <div v-if="item.children.length>1" class="yaxis1"></div>
                <div class="line"></div>
                <div style="margin: 15px 0;">
                  <div class="d_flex">
                    <div class="avtor"><img :src="itemChildren.avatar" alt=""></div>
                    <div class="phone">{{ itemChildren.phone }}</div>
                    <div class="name">{{ itemChildren.nickname }}</div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      SaleRelation: {}
    }
  },
  methods: {
    getDataList(userId) {
      this.$http({
        url: this.$http.adornUrl(`/sale/saleRelation/saleRelationStatistics/info/${userId}`),
        method: "get"
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.SaleRelation = data.SaleRelationStatisticsDetailsVo
        }
      });
    },
    goBack() {
      this.$emit('goBack')
    },
    setMargin(type, index, arr, parentArr) {
      if(type === 1) {
        if(index === parentArr.length-1) {
          if(arr.length > 0) {
            return - arr.length*80/2 + 'px'
          } else {
            return '-40px'
          }
        } else {
          return 0
        }
      }
      if(type === 2) {
        if(index === 0) {
          if(arr.length > 0) {
            return - arr.length*80/2 + 'px'
          } else {
            return '-40px'
          }
        } else {
          return 0
        }
      }
      if(type === 3) {
        if(index === 0 || index === parentArr.length-1) {
          if(arr.length === 0) {
            return '40px'
          } else {
            return arr.length*80/2 + 'px'
          }
        } else {
          if(arr.length === 0) {
            return '80px'
          } else {
            return arr.length*80 + 'px'
          }
        }
      }
    }
  }
};
</script>
<style lang="scss" scoped>
  .relationContent{
  }
  img{
    width: 100%;
    border-radius: 2px;
  }
  .line{
    height: 1px;
    width: 50px;
    background: #000;
  }
  .first{
    display: flex;
    align-items: center;
  }
  .yaxis{
    height: 80px;
    width: 1px;
    background: #000;
  }
  .yaxis1{
    height: 80px;
    width: 1px;
    background: #000;
  }
  .d_flex{
    margin-left: 10px;
    width: 270px;
    height: 50px;
    border-radius: 2px;
    display: flex;
    justify-content: center;
    border: 1px solid #efefef;
    align-items: center;
    .avtor{
      width: 30px;
    }
    .phone{
      margin: 0 5px;
    }
    .name{
      width: 120px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow:ellipsis;
    }
  }
  .second>div:first-child .yaxis{
    height: 40px;
    margin-bottom: -40px;
  }
  .second>div:last-child .yaxis{
    height: 40px;
    margin-top: -40px;
  }
  .second1>div:first-child .yaxis1{
    height: 40px;
    margin-bottom: -40px;
  }
  .second1>div:last-child .yaxis1{
    height: 40px;
    margin-top: -40px;
  }
</style>

